
import grails.test.*

class UserTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testInvalidPwd() {
		mockForConstraintsTests(User)
		def pwd = ""
		User u = new User(password: pwd)
		assertFalse "Empty password should not allowed", u.validate()
		assertEquals "blank", u.errors["password"]
		
	
    }
	
	void testNormal() {
		def u1 = new User(userName: "user1", password: "pwd1", firstName: "user first name 1")
		def u2 = new User(userName: "user2", password: "pwd_2", firstName: "user first name 2")
		mockDomain(User, [u1, u2])
		
		u1.save()
		u2.save()
		
		assertEquals(2, User.count())
		
		// Assert password encryption( it doesn't work for now)
//		assertEquals 32, User.findByUserName("user1").password.length()
//		assertEquals 32, User.findByUserName("user2").password.length()

		u1.delete()
		assertEquals(1, User.count())
		
		
	}
}
